package cn.itcast.test;

import cn.itcast.domain.CollectionBean;
import cn.itcast.domain.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Collection;

/**
 * Created by lenovo on 2018/6/8.
 */
public class Injection {
    @Test//set注入
    public void test1(){
        ApplicationContext ac=new ClassPathXmlApplicationContext("cn/itcast/test/applicationContext.xml");
        User user=(User)ac.getBean("User");
        System.out.println(user);
    }
    @Test//构造方法注入
    public void test2(){
        ApplicationContext ac=new ClassPathXmlApplicationContext("cn/itcast/test/applicationContext.xml");
        User user=(User)ac.getBean("U1");
        System.out.println(user);
    }
    @Test//p名称空间注入
    public void test3(){
        ApplicationContext ac=new ClassPathXmlApplicationContext("cn/itcast/test/applicationContext.xml");
        User user=(User)ac.getBean("U2");
        System.out.println(user);
    }
    @Test//spel表达式注入
    public void test4(){
        ApplicationContext ac=new ClassPathXmlApplicationContext("cn/itcast/test/applicationContext.xml");
        User user=(User)ac.getBean("U3");

        System.out.println(user);
    }
    @Test//复杂类型注入
    public void test5(){
        ApplicationContext ac=new ClassPathXmlApplicationContext("cn/itcast/test/collectionBean.xml");
        CollectionBean collectionBean=(CollectionBean)ac.getBean("CollectionBean");

        System.out.println(collectionBean);
    }
}
